#include "algostuff.h"
#include <cstdlib>
#include <random>
using namespace std;

void shuffle1()
{
	vector<int> coll;

	INSERT_ELEMENTS(coll, 1, 9);
	PRINT_ELEMENTS(coll, "coll: ");

	// shuffle all elements randomly
	random_shuffle(coll.begin(), coll.end());

	PRINT_ELEMENTS(coll, "shuffled: ");

	// sort them again
	sort(coll.begin(), coll.end());
	PRINT_ELEMENTS(coll, "sorted: ");

	// shuffle elements with default engine
	default_random_engine dre;
	shuffle(coll.begin(), coll.end(), dre);

	PRINT_ELEMENTS(coll, "shuffled: ");
}

class MyRandom
{
public:
	ptrdiff_t operator() (ptrdiff_t max)
	{
		cout << max << endl;
		double tmp;
		tmp = static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
		return static_cast<ptrdiff_t>(tmp * max);
	}
};

void shuffle2()
{
	vector<int> coll;

	INSERT_ELEMENTS(coll, 10, 19);
	PRINT_ELEMENTS(coll, "coll: ");

	// shuffle elements with self-written random-number generator
	MyRandom rd;
	random_shuffle(coll.begin(), coll.end(), rd);

	PRINT_ELEMENTS(coll, "shuffled: ");
}